package com.test.io.raderWriter;

import org.junit.Test;

import java.io.FileReader;
import java.io.IOException;

// 字符流输入流练习
public class FileReaderDemo {
    // 使用 FileReader 读取指定文件数据并显示到控制台
    @Test
    public void readFile() {
        FileReader fileReader = null;
        try {
             fileReader = new FileReader("d:\\newFile2.text");
             char[] readData = new char[1024];
             int index = 0;
             while((index = fileReader.read(readData)) != -1) {
                 System.out.print(new String(readData, 0, index));
             }
             fileReader.read();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(fileReader != null) {
                    fileReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
